package com.bishe.demo.modules.tourism.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.common.entity.SearchBean;
import com.bishe.demo.modules.tourism.entity.Route;
import com.bishe.demo.modules.tourism.entity.RouteSearchBean;
import com.bishe.demo.modules.tourism.service.impl.RouteServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description RouteController
 * @Author Lubb
 * @Date 2021/3/29 15:35
 */
@RestController
@RequestMapping("/api")
public class RouteController {
    @Autowired
    private RouteServiceImpl routeService;

    /**
     * 127.0.0.1/api/route  ---  post
     * {"title":"aaa","introduction":"bbb","startPoint":"cdc","terminalPoint":"pk","type":"zz","price":"100000","level":"5","fkSupplierId":1,"fkCoverImageId":1,"viaPoint":[{"id":"11"}]}
     */
    @PostMapping("/route")
    ResultEntity<Route> addRoute(@RequestBody Route route) {
        return routeService.addRoute(route);
    }

    /**
     * 127.0.0.1/api/route/1 --- delete
     */
    @DeleteMapping("/route/{id}")
    ResultEntity<Route> deleteRouteById(@PathVariable Integer id) {
        return routeService.deleteRouteById(id);
    }

    ;

    /**
     * 127.0.0.1/api/route  ---- put
     * {"id":"2","title":"成都-秦皇岛","introduction":"好","startPoint":"成都","terminalPoint":"秦皇岛","type":"zz","price":"100000","level":"5","fkSupplierId":1,"fkCoverImageId":1,"viaPoint":[{"id":"1303"}]}
     */
    @PutMapping("/route")
    ResultEntity<Route> updateRoute(@RequestBody Route route) {
        return routeService.updateRoute(route);
    }

    ;

    /**
     * 127.0.0.1/api/route/2 --- get
     */
    @GetMapping("/route/{id}")
    Route getRouteById(@PathVariable Integer id) {
        return routeService.getRouteById(id);
    }

    ;

    @GetMapping("/routes")
    public List<Route> getRoutes() {
        return routeService.getRoutes();
    }

    @PostMapping("/routes")
    public PageInfo<Route> getRoutesBySearchBean(@RequestBody RouteSearchBean searchBean) {
        return routeService.getRoutesBySearchBean(searchBean);
    }
}
